package com.buddy.sds.auth.utils;

import com.buddy.sds.auth.entity.SystemUser;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

public class AuthUtil {

    private AuthUtil(){

    }

    public static SystemUser getCurrentUser(){

        Subject subject = SecurityUtils.getSubject();

        if(subject.isAuthenticated()){
            return (SystemUser) subject.getPrincipal();
        }

        return null;
    }
    public static boolean hasRole(String role){

        Subject subject = SecurityUtils.getSubject();
        if(subject.isAuthenticated()){
            return subject.hasRole(role);
        }
        return false;
    }
}
